package com.njtoyo.taxi.admin.rest.controller.platform;

import cn.hutool.core.lang.Dict;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njtoyo.taxi.admin.aop.PassToken;
import com.njtoyo.taxi.admin.mapper.master.entity.DriverDeviceAutoVersion;
import com.njtoyo.taxi.admin.mapper.secondary.enums.VersionModel;
import com.njtoyo.taxi.admin.mapper.secondary.enums.VersionUserGroup;
import com.njtoyo.taxi.admin.rest.wrapper.platform.appVersion.AppVersionWrapper;
import com.njtoyo.taxi.admin.service.platform.CarAppVersionService;
import com.njtoyo.taxi.admin.service.platform.VersionService;
import com.taxi.entity.common.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/platform/car-app-version")
public class CarAppVersionController {

    @Autowired
    private CarAppVersionService carAppVersionService;


    @GetMapping("/list")
    public RestResult list(@RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                           @RequestParam(value = "size", required = false, defaultValue = "15") Integer size,
                           @RequestParam(value = "title", required = false) String title,
                           @RequestParam(value = "model", required = false) VersionModel model,
                           @RequestParam(value = "userGroup", required = false) VersionUserGroup userGroup) {
        return carAppVersionService.list(current, size, title, model, userGroup);
    }

    @GetMapping("/getDeviceList/{id}")
    public RestResult getDeviceList(@PathVariable("id") Long id) {
        return carAppVersionService.getDeviceList(id);
    }


    @GetMapping("/getInfo/{id}")
    public RestResult getInfo(@PathVariable("id") Long id) {
        return carAppVersionService.getInfo(id);
    }

    @GetMapping("/getDeviceVendor")
    public RestResult getDeviceVendor() {
        return carAppVersionService.getDeviceVendor();
    }

    @PostMapping("/upgradeDevices")
    public RestResult upgradeDevices(@RequestBody Dict dict) {
        Long id = MapUtil.getLong(dict, "id");
        if (ObjectUtil.isNull(id)) {
            return RestResult.failed("缺少必要参数: id");
        }
        String deviceIds = MapUtil.getStr(dict, "deviceIds");
        if (StrUtil.isBlank(deviceIds)) {
            return RestResult.failed("请选择要升级的设备");
        }
        return carAppVersionService.upgradeDevices(id, deviceIds);
    }


    @PostMapping("/add")
    RestResult add(@RequestBody DriverDeviceAutoVersion version) {
        return carAppVersionService.add(version);
    }

    @PostMapping("/update/{id}")
    RestResult updateById(@PathVariable("id") Long id, @RequestBody DriverDeviceAutoVersion version) {
        return carAppVersionService.updateById(id,version);
    }

    @PostMapping("/clearDetail/{id}")
    RestResult clearDetail(@PathVariable("id") Long id) {
        return carAppVersionService.clearDetail(id);
    }


}
